


var review;
var id=getmessage('id');
$.ajax({
        type:'get',
        url:'/posts/'+id,
        success:function(res){
            var html=template('postTpl',{data:res});
            $("#article").html(html);

        }
});

$('#article').on('click','#good',function(){
    $.ajax({
        type:'post',
        url:'/posts/fabulous/'+id,
        success:function(){
            alert('赞')
        }
    })
});

$.ajax({
    type:'get',
    url:'/settings',
    success:function(res){
      
        review=res.review;
        if(res.comment){
            var html=template('pinglun');
            $("#comment").html(html);
        }
    }
});

$("#comment").on('submit','#commentForm',function(){
    var state;
    var contents=$(this).find('textarea').val();
        if(review){
            state=0;
        }else{
            state=1;
        }
        $.ajax({
            type:'post',
            url:'/comments',
            data:{
                content:contents,
                post:id,
                state:state
            },
            success:function(){
               alert('评论成功');
               location.reload()
            },
            error:function(){
                alert('评论失败')
            }
        })
        return false
})